package com.heima.behavior.listener;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.dto.FollowBehaviorDto;
import com.heima.behavior.service.IApFollowBehaviorService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author: GQ
 * @create: 2022-08-03 15:39
 */
@Slf4j
@Component
public class FollowBehaviorListener {

    @Autowired
    private IApFollowBehaviorService followBehaviorService;


    /**
     * 完成监听关注行为操作日志
     * @param record
     */
    @KafkaListener(topics = "${topic.followBehaviorTopic}")
    public void followBehaviorSave(ConsumerRecord<String, String> record){
        String value = record.value();
        if(StringUtils.isNotBlank(value)){
            log.info("【行为微服务】监听到关注行为话题，{}", value);
            FollowBehaviorDto followBehaviorDto = JSON.parseObject(value, FollowBehaviorDto.class);
            followBehaviorService.followBehaviorSave(followBehaviorDto);
        }
    }
}
